#include "game_logic.h"
#include "ltclientshell.h"
#include <iltclient.h>
#include "iltmessage.h"

void game_logic::on_message(ILTMessage_Read* pMsg) {
    pMsg->SeekTo(0) ;
    uint8 id = pMsg->Readuint8() ;
    m_message_manager.deal_with_message(id, pMsg) ;
}

void game_logic::render() {
	
    LTRESULT result ;
    float frame_time = g_pLTClient->GetFrameTime() ;

    result = g_pLTClient->ClearScreen(NULL, CLEARSCREEN_SCREEN | CLEARSCREEN_RENDER, 0) ;
    if(LT_OK != result) {
        g_pLTClient->DebugOut("Error in ClearScreen() \n") ;
        g_pLTClient->Shutdown() ;
    }

    result = g_pLTClient->Start3D() ;
    if(LT_OK != result) {
        g_pLTClient->DebugOut("Error in Start3D()\n") ;
        g_pLTClient->Shutdown() ;
    }

    do_render_3d(frame_time) ;
    g_pLTClient->StartOptimized2D() ;
    do_render_2d(frame_time) ;
    g_pLTClient->EndOptimized2D() ;

    shell()->render_ui() ;
    result = g_pLTClient->End3D(END3D_CANDRAWCONSOLE) ;
    if(LT_OK != result) {
        g_pLTClient->DebugOut("Error in End3D()\n") ;
        g_pLTClient->Shutdown() ;
    }

    shell()->render_fx() ;
    result = g_pLTClient->FlipScreen(NULL) ;
    if(LT_OK != result) {
        g_pLTClient->DebugOut("Error in FlipScreen() \n") ;
        g_pLTClient->Shutdown() ;
    }
}



game_logic::~game_logic() {
}


